﻿using Collaboration_System.DataBase;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static MaterialDesignThemes.Wpf.Theme;

namespace Collaboration_System
{
    /// <summary>
    /// Логика взаимодействия для LidsWindow.xaml
    /// </summary>
    public partial class LidsWindow : Window
    {
        Collaboration_SystemEntities entity = new Collaboration_SystemEntities();
        public List<Notes> notes;
        public List<Users> users;
        public List<Lids> lids;
        private string path = @"Notes.txt";
        public LidsWindow()
        {
            InitializeComponent();

        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            RefreshTable();
            string idUserString = File.ReadLines("config.json").Skip(1).First();
            UserName.Text = idUserString;
            string idRoleString = File.ReadLines("config.json").Skip(2).First();
            Role.Text = idRoleString;
            if (!File.Exists(path))
            {
                File.Create(path);
            }
        }
        private void RefreshTable()
        {
            clientsDG.ItemsSource = entity.Lids.ToList();
        }
        private void Task_Click(object sender, RoutedEventArgs e)
        {
            TaskWindow autorization = new TaskWindow();
            autorization.Show();
            Close();
        }

        private void Lids_Click(object sender, RoutedEventArgs e)
        {
            LidsWindow autorization = new LidsWindow();
            autorization.Show();
            Close();
        }

        private void Deal_Click(object sender, RoutedEventArgs e)
        {
            TransactionsWindow autorization = new TransactionsWindow();
            autorization.Show();
            Close();
        }

        private void Company_Click(object sender, RoutedEventArgs e)
        {
            CompanyWindow autorization = new CompanyWindow();
            autorization.Show();
            Close();
        }

        private void Product_Click(object sender, RoutedEventArgs e)
        {
            ProductWindow autorization = new ProductWindow();
            autorization.Show();
            Close();
        }

        private void ExitAkk_Click(object sender, RoutedEventArgs e)
        {
            File.Delete("config.json");
            Autorization autorization = new Autorization();
            autorization.Show();
            Close();
        }
        private void Home_Click(object sender, RoutedEventArgs e)
        {
            Dashboard autorization = new Dashboard();
            autorization.Show();
            Close();
        }

        private void ClouseButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Close();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {

        }

        private void DeleteData_Click(object sender, RoutedEventArgs e)
        {
            var message = MessageBox.Show("Вы точно хотите удалить данные?", "Уведомление", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (message.Equals(MessageBoxResult.Yes))
            {
                var selected = clientsDG.SelectedItem as Lids;
                if (selected != null)
                {
                    entity.Lids.Remove(selected);
                    entity.SaveChanges();
                    MessageBox.Show("Данные были успешно удалены", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
                    RefreshTable();

                }
                else
                {
                    MessageBox.Show("Вы не выбрали строку для удаления!", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
    }
}
